package com.nico.chatvoiceview

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.util.Log
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.WindowManager
import com.nico.voiceview.R

class LanguageDialog:Dialog {
    lateinit var mBottomLayout:View
    constructor(context: Context) : this(context,0) {

    }
    constructor(context: Context, themeResId:Int) : super (context,themeResId) {
        initView(context)
    }

    private fun initView(context: Context) {
        val inflate =
            LayoutInflater.from(context).inflate(R.layout.dialog_language_layout, null, false)
        setContentView(inflate)
        mBottomLayout = inflate.findViewById<View>(R.id.bottom_layout)
        window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        val params: WindowManager.LayoutParams = window!!.attributes
        params.width = WindowManager.LayoutParams.MATCH_PARENT
        params.height = WindowManager.LayoutParams.MATCH_PARENT
        window!!.setAttributes(params)
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        if(event.y<mBottomLayout.top){
            dismiss()
        }
        Log.d(javaClass.simpleName, "adjustLayoutForKeyboard1 ======isShowing:${mBottomLayout.top} ${mBottomLayout.y}  ${event.rawY}  ${event.y}")
        return super.onTouchEvent(event)
    }
}